<?php

class WenzhangController extends Zend_Controller_Action
{

    public function init()
    {
		//设置首页引用css
		$this->view->headLink()->appendStylesheet($this->view->baseUrl().'/css/article.css');
    }

    public function indexAction()
    {
		//设置首页引用js
		$this->view->headScript()->appendFile($this->view->baseUrl().'/js/index_flash.js');
        //设置title
		$this->view->headTitle("珠宝玉石文摘");
		//设置关键词（seo）
		$this->view->headMeta()->appendName('keywords', '翡翠,岫玉,和田玉,玉石,珠宝');
		//设置描述（seo）
		$this->view->headMeta()->appendName('description','珠宝玉石文摘，汇聚各类珠宝玉石相关的新闻、文章和摘要。翡翠、岫玉、和田玉等玉石相关的知识及介绍');
		$db_article=new Application_Model_DbTable_Article();
		$this->view->hotArticleList=$db_article->getHotArticle(30);
		$this->view->newsList=$db_article->getArticleList(0,30);
		$this->view->digestList=$db_article->getArticleList(1,30);
		$this->view->knowledgeList=$db_article->getArticleList(2,30);
		//$this->view->articleNewsList=$db_article->get
    }

    public function contentAction()
    {
        //查询文章信息
        $articleId=$this->getRequest()->getParam('id');
        $articleModel=new Application_Model_DbTable_Article();
        $article=$articleModel->getArticleById($articleId);
    	//设置title
        $this->view->headTitle($article->article_title);
        //设置关键词（seo）
        $this->view->headMeta()->appendName('keywords', $article->article_key_words);
        //设置描述（seo）
        $this->view->headMeta()->appendName('description',$article->article_description);
        //文章标题
        $this->view->title=$article->article_title;
        //创建时间
        $this->view->create_date=$article->article_create_date;
        //文章内容
        $this->view->content=$article->article_content;
        //拆分关键词
        $keywds=explode(",", $article->article_key_words);
        $this->view->keywds=$keywds;
        //浏览次数
        $count=$article->article_count_num;
        $this->view->count=$count;
        $count++;
        $articleModel->updateCount($articleId, $count);
        //文章出处
        if(0==$article->article_type){
            $this->view->from="文章来源：淘岫玉网站原创 转载请注明";
        }
        if(1==$article->article_type){
            $from="文章来源：淘岫玉网站编辑";
            if(null!=$article->article_from&&""!=$article->article_from){
                $from.=" 原出处：".$article->article_from;
            }
            $this->view->from=$from;
        }
        if(2==$article->article_type){
        	$from="文章来源：淘岫玉网站转载";
        	if(null!=$article->article_from&&""!=$article->article_from){
    			$from.=" 原出处：".$article->article_from;
    		}
        	$this->view->from=$from;
        }
        $this->view->sideBar=1;
        //边栏热门文章列表
        $this->view->hotArticles=$articleModel->getHotArticle(15);
        //边栏热门商品列表
        $itemsModel=new Application_Model_DbTable_TaobaoItems();
        $this->view->hotItems=$itemsModel->getSidebarHotItems();
        
        //热门关键词
        $keywordsModel=new Application_Model_DbTable_Keywords();
        $this->view->keyWordsList=$keywordsModel->getHotKeyWords();
    }

    public function listAction(){
		// action body
		$contentType=$this->getRequest()->getParam('content_type');
        if(null==$contentType){
        	$this->view->contentType="全部文章列表";
        }else{
    		if(0==$contentType){
    			$this->view->contentType="新闻类文章列表";
    		}
    		if(1==$contentType){
    			$this->view->contentType="文摘类文章列表";
    		}
    		if(2==$contentType){
    			$this->view->contentType="知识类文章列表";
    		}
        }
		$config=new Zend_Config_Ini(APPLICATION_PATH."/configs/application.ini",'production');
		$db = Zend_Db::factory($config->resources->db);
		$selecter=$db->select()->from('txy_article',array('article_id','article_title','article_url_spell','article_content_type','article_create_date'))->order('article_create_date desc');
		//$adapter=new Txy_Extends_TempTaobaoPageinator($db->select()->from('txy_temp_taobao')->where('item_status=2'));
		if(null!=$contentType){
			$intContentType=(int)$contentType;
			if(0==$intContentType){
				$selecter->where('article_content_type=0');
			}
			if(1==$intContentType){
				$selecter->where('article_content_type=1');
			}
			if(2==$intContentType){
				$selecter->where('article_content_type=2');
			}
		}
		$adapter = new Zend_Paginator_Adapter_DbSelect($selecter);
		$paginator = new Zend_Paginator($adapter);
		$paginator->setItemCountPerPage(25);
		$paginator->setCurrentPageNumber($this->_getParam('page'));
		$this->view->paginator = $paginator;
		$articleModel=new Application_Model_DbTable_Article();
		$this->view->sideBar=1;
		$this->view->hotArticles=$articleModel->getHotArticle(15);
		//边栏热门商品列表
		$itemsModel=new Application_Model_DbTable_TaobaoItems();
		$this->view->hotItems=$itemsModel->getSidebarHotItems(2);
		//热门关键词
		$keywordsModel=new Application_Model_DbTable_Keywords();
		$this->view->keyWordsList=$keywordsModel->getHotKeyWords();
    }


}





